using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PowerGo.Engine
{
    public class DummyForm : Form
    {
        protected override void OnLoad(EventArgs e2)
        {
            base.OnLoad(e2);
        }

    }

    internal class Program
    {
        const string name = "powergo_engine";
        private static Mutex m;

 
        static void Main(string[] args)
        {

            bool firstInstance;
            m = new Mutex(false, name, out firstInstance);
            if (!firstInstance)
            {
                return;
            }
            Core();
            m.ReleaseMutex();
            m.Close();
            return;
        }

        private static void Core()
        {
            var application = Marshal.GetActiveObject("PowerPoint.Application") as Microsoft.Office.Interop.PowerPoint.Application;

            using (var mouseHook = new GlobalMouseHook())
            {
                // 鼠标释放事件
                mouseHook.MouseUp += (sender, e) =>
                {
                    if (e.Button != MouseButtons.Right) return;
                    try
                    {
                        var slideShowWindow = application.ActivePresentation.SlideShowWindow.HWND;
                        application.Run("MouseRightButtonDown", e.X, e.Y);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                };

                Console.WriteLine("PowerGo Engine 生效中...");

                mouseHook.Start();
                Application.Run();
            }
        }
    }
}
